//
// Created by xili on 2024/9/5 9:54.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    bool check(string x, string y) {
        int h[26] = {0};
        for (auto c: x) h[c - 'a']++;
        for (auto c: y) {
            bool canFind = false;
            for (int i = int(c - 'a'); i < 26; ++i) {
                if (h[i] > 0) {
                    --h[i];
                    canFind = true;
                    break;
                }
            }
            if (!canFind) return false;
        }
        return true;
    }

    bool checkIfCanBreak(string s1, string s2) {
        return check(s1, s2) || check(s2, s1);
    }
};